package 牛客_面试必刷.Month07.day13;

import java.util.ArrayList;

public class 没有重复项数字的全排列问题 {
    ArrayList<ArrayList<Integer>> lists = new ArrayList<>();
    ArrayList<Integer> list = new ArrayList<>();
    public ArrayList<ArrayList<Integer>> permute(int[] num) {
        backstacking(num);
        return lists;
    }

    public void backstacking(int[] nums){
        if(list.size() == nums.length){
            lists.add(new ArrayList<>(list));
        }

        for (int i = 0; i < nums.length; i++) {
                if(list.contains(nums[i])) continue;
                list.add(nums[i]);
                backstacking(nums);
                list.remove(list.size() - 1);
        }
    }
}
